package vek.GUI;

import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.*;
import util.ImageGetter;
import vek.ObjectDatabase.DatabaseConnector;
import vek.XML.Parsers.XMLParserMain;
import vek.XML.parsedObjects.ParsedMap;

/**
 * This class is responsible for creating the main JFrame and giving the background image of the city as a paramater
 * @author Christian, Michal og Jakob (Hold 1, gruppe 2)
 */
public class GUIMain {
    
    private Dimension screenSize;
    
    /**
     * The constructor parses the map.xml files using parseXMLAndReturnParsedMap and gets the backgroundImage using ImageGetter and creates a new MainWindow
     * @param dbc the database connector used in this program
     */
    
    public GUIMain(DatabaseConnector dbc)
    {
        setUILookAndFeel();
        screenSize = new Dimension(
                (int)(Toolkit.getDefaultToolkit().getScreenSize().getWidth() ),
                (int)(Toolkit.getDefaultToolkit().getScreenSize().getHeight() ));
        
        ParsedMap parsedMap = XMLParserMain.parseXMLAndReturnParsedMap("Data/map.xml");
        Image img = ImageGetter.getImage(parsedMap.getBackgroundFilename());
        new MainWindow(new Dimension((int)(screenSize.getWidth() * 0.9), (int)(screenSize.getHeight() * 0.85)), new Dimension(parsedMap.getWidthOfBackground(), parsedMap.getHeightOfBackground()), img, dbc);


    }
    
  
    
    /**
     * Changes the Look and Feel, that is the overall look of the program. Can be either normal Java, Windows, Mac or Linux look. 
     * Currently uses System specifik L&F
     */
    
    private void setUILookAndFeel()
    {
        try {
	    // Set System L&F
            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } 
    catch (Exception e) {
        System.err.println("cannot add L&F");
    }
    
    }

}
